package com.njupt.sellsec.dao;

import com.njupt.sellsec.domain.OrderInfo;
import com.njupt.sellsec.domain.SecOrder;
import org.apache.ibatis.annotations.*;

/**
 * @Author: XJL
 * @Description:
 * @Date: Create in 19:08 2018/7/29
 * @Modified By:
 **/
public interface SecOrderDao {

   @Select("select * from sec_order where user_id=#{userId} and goods_id=#{goodId}")
   SecOrder getSecOrderByUserIdAndGoodsId(@Param("userId") long userId, @Param("goodId") long goodId);

   @Insert("insert into sec_order (user_id, order_id, goods_id) values(#{userId},#{orderId},#{goodsId})")
   long saveSecOrder(SecOrder secOrder);

   //为了防止订单重复，应该给在表中建一个唯一索引，在user_id和goodd_id上建一个联合唯一索引
   @Insert("insert into order_info (user_id, goods_id, delivery_addr_id, goods_name, goods_count,goods_price,order_channel,status,create_date,pay_date) values (" +
           "#{userId},#{goodsId},#{deliveryAddrId},#{goodsName},#{goodsCount},#{goodsPrice},#{orderChannel},#{status},#{createDate},#{payDate})")
   @SelectKey(keyColumn = "id",keyProperty = "id",resultType = long.class,before = false,statement = "select last_insert_id()")
   long saveOrderInfo(OrderInfo orderInfo);

   @Delete("delete from order_info")
    void deleteOrders();

   @Delete("delete from sec_order")
   void deleteSecSellOrders();
}
